Counting Regexp

Hello Forums,

Is it possible to count the regexp

I have a string in this form in object text = [It_ 6], [It_3],....etc

Regexp Verweis = regexp2 "\\[[I][t][_]+([0-9]+)\\]"



I would like to find all strings in my object

How do I do this in regex please?

 

Regards,

Neven


Control17 - Wed Aug 23 02:55:55 EDT 2017

Re: Counting Regexp
Mike.Scharnow - Wed Aug 23 05:21:01 EDT 2017

Hi Neven,

have a look at the DXL manual, explanation of regexp2, example program. Use the while loop for counting.

Regards,
Mike

Re: Counting Regexp
Control17 - Wed Aug 23 06:11:08 EDT 2017

Mike.Scharnow - Wed Aug 23 05:21:01 EDT 2017

Hi Neven,

have a look at the DXL manual, explanation of regexp2, example program. Use the while loop for counting.

Regards,
Mike

Hi,

i tried with this code

pragma runLim, 0
Module m = current
Object o
filtering off

Skip objList = create() 
for o in m do {
 {
 Regexp Reference = regexp2 "\\[[I][t][_]+([0-9]+)\\]"
 string theText = (o."Object Text" "")(o."Object Heading")
 int count = 0
  while (!null theText && Reference theText) {
  theText = theText[end 1 + 1:]
  count++
 string ReferenceNumber  
 if (Reference theText) {
    ReferenceNumber  = theText[match 1]
    int iReferenceNumber = intOf realOf ReferenceNumber
    put (objList,iReferenceNumber,o)
   }                                                                        
  }
 }
}
  

but i does not find all the Reference  No
should i convert "theText" to buffer

 

Regards,

Neven

 

Re: Counting Regexp
Control17 - Wed Aug 23 09:01:28 EDT 2017

Control17 - Wed Aug 23 06:11:08 EDT 2017

Hi,

i tried with this code

pragma runLim, 0
Module m = current
Object o
filtering off

Skip objList = create() 
for o in m do {
 {
 Regexp Reference = regexp2 "\\[[I][t][_]+([0-9]+)\\]"
 string theText = (o."Object Text" "")(o."Object Heading")
 int count = 0
  while (!null theText && Reference theText) {
  theText = theText[end 1 + 1:]
  count++
 string ReferenceNumber  
 if (Reference theText) {
    ReferenceNumber  = theText[match 1]
    int iReferenceNumber = intOf realOf ReferenceNumber
    put (objList,iReferenceNumber,o)
   }                                                                        
  }
 }
}
  

but i does not find all the Reference  No
should i convert "theText" to buffer

 

Regards,

Neven

 

have any one another idea Frown

Re: Counting Regexp
Mike.Scharnow - Wed Aug 23 12:58:11 EDT 2017

Control17 - Wed Aug 23 09:01:28 EDT 2017

have any one another idea Frown

Half

What do you think the code you inserted does? Did you understand the lines at all?

In line 13 you remove the reference from theText, so the second pattern matching in line 16 will not be able find the reference anymore... And it is not needed, as you already executed the regexp against the string....

 

pragma runLim, 0
Module m = current
Object o
filtering off

Skip objList = create() 
Regexp Reference = regexp2 "\\[[I][t][_]+([0-9]+)\\]"
for o in m do {
  {
    string theText = (o."Object Text" "")(o."Object Heading" "")
    int count = 0
    while (!null theText && Reference theText) {
      count++
      string ReferenceNumber  
      ReferenceNumber  = theText[match 1]
      int iReferenceNumber = intOf realOf ReferenceNumber
      put (objList,iReferenceNumber,o)
      theText = theText[end 1 + 1:]
    }
    print "Object " (o."Absolute Number" "") " contains " count " references.\n"
  }
}

 

[progress] Executing /x.dxl
Object 2 contains 1 references.
Object 3 contains 0 references.
Object 4 contains 1 references.
Object 5 contains 3 references.
Object 6 contains 1 references.
Object 7 contains 0 references.

[progress] Done.

Re: Counting Regexp
Mike.Scharnow - Wed Aug 23 13:04:06 EDT 2017

hm, I wanted to attach a screenshot of my demo module in the previous post, but IBM keeps telling me that the image is considered as spam...


Attachments

2017-08-23 18_55_17-'references' current 0.0 in _Support (Fo.png

Re: Counting Regexp
Control17 - Thu Aug 24 03:03:53 EDT 2017

Mike.Scharnow - Wed Aug 23 12:58:11 EDT 2017

Half

What do you think the code you inserted does? Did you understand the lines at all?

In line 13 you remove the reference from theText, so the second pattern matching in line 16 will not be able find the reference anymore... And it is not needed, as you already executed the regexp against the string....

 

pragma runLim, 0
Module m = current
Object o
filtering off

Skip objList = create() 
Regexp Reference = regexp2 "\\[[I][t][_]+([0-9]+)\\]"
for o in m do {
  {
    string theText = (o."Object Text" "")(o."Object Heading" "")
    int count = 0
    while (!null theText && Reference theText) {
      count++
      string ReferenceNumber  
      ReferenceNumber  = theText[match 1]
      int iReferenceNumber = intOf realOf ReferenceNumber
      put (objList,iReferenceNumber,o)
      theText = theText[end 1 + 1:]
    }
    print "Object " (o."Absolute Number" "") " contains " count " references.\n"
  }
}

 

[progress] Executing /x.dxl
Object 2 contains 1 references.
Object 3 contains 0 references.
Object 4 contains 1 references.
Object 5 contains 3 references.
Object 6 contains 1 references.
Object 7 contains 0 references.

[progress] Done.

Shy thank u